package cenas;

import assets.Botao;
import pi.beta.GerenciamentoDeCenasEEntrada;

import org.anddev.andengine.audio.sound.SoundManager;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.TextureManager;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import android.content.Context;

public class Controles extends Scene {

	public int largura;
	public int altura;
	Botao sair;
	
	Context contexto;
	TextureManager tm;
	GerenciamentoDeCenasEEntrada trocaDeCenas;
	
	private BitmapTextureAtlas mapaDeTexturas, mapaDeTexturas2;
	private TextureRegion regiaoDaTextura, regiaoDaTextura2;

	public Controles(GerenciamentoDeCenasEEntrada trocaDeCenas, Context contexto, int largura, int altura, TextureManager tm, SoundManager sm){
		this.contexto = contexto;
		this.trocaDeCenas = trocaDeCenas;
		this.tm = tm;
		mapaDeTexturas = new BitmapTextureAtlas(1024, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		mapaDeTexturas2 = new BitmapTextureAtlas(1024, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		regiaoDaTextura = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas, contexto, "Cenario.png", 0, 0);
		regiaoDaTextura2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas2, contexto, "Controles.png", 0, 0);
		tm.loadTexture(mapaDeTexturas);
		tm.loadTexture(mapaDeTexturas2);
		Sprite cenario = new Sprite(0, 0, regiaoDaTextura);
		Sprite informacoes = new Sprite(0, 0, regiaoDaTextura2);
		attachChild(cenario);
		attachChild(informacoes);
		sair = new Botao("Botao.png", this, contexto, tm);
		sair.sprite.setPosition(sair.sprite.getX(), 320);
	}
	
	@Override
	public boolean onSceneTouchEvent(TouchEvent toque) {
		//return super.onSceneTouchEvent(pSceneTouchEvent);
		
		if (toque.getAction() == TouchEvent.ACTION_DOWN) {
			//if(toque.getX() > 240 && toque.getY() > 256
				//&& toque.getX() < 560 && toque.getY() < 320) {
				trocaDeCenas.carregaCena(trocaDeCenas.MENU_PRINCIPAL);
			//}
			return true;
		}
		return false;
	}

}
